import {getPerson} from '@/services/person'

export default {
    //命令空间,dispatch时通过命令空间调用model
    namespace: "person",

    //保存状态与数据
    state: {
        persons: []
    },

    //发起网络请求,获取影响状态的数据,将数据交给reducers
    effects: {
        //call,调用请求  put将数据传递给reducers
        * fetchPersons(_, {call, put}) {
            const data = yield call(getPerson)
            yield put({
                type: "setPersons",
                payload: data,
            })
        }
    },

    //通过reducers更新状态, 纯函数
    reducers: {
        setPersons(state, action) {
            return {
                ...state,
                persons: action.payload
            }
        }
    }

}